<template>
  <div>
    <van-nav-bar title="地址列表"
                 left-text="返回"
                 left-arrow />
    <van-address-list v-model="chosenAddressId"
                      :list="addressList"
                      default-tag-text="默认"
                      @add="onAdd"
                      @edit="onEdit"
                      @click-item="selAddress" />
  </div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
import { setDefaultApi } from '../../api/address'
export default {
  methods: {
    ...mapActions("addressStore", ["getAddressAction"]),
    onAdd () {
      this.$router.push({ name: "addressEdit" })
    },
    onEdit (item) {
      console.log(item)
      this.$router.push({ name: "addressEdit", params: { addObj: item } })
    },
    async selAddress (item) { //设置默认地址
      console.log(item)
      var res = await setDefaultApi(item.id)
      console.log(res)
      this.$router.push({ name: "order" })//跳回订单页
    }
  },
  created () {
    this.getAddressAction();
  },
  computed: {
    ...mapGetters("addressStore", ["addressList"])
  },
  data () {
    return {
      chosenAddressId: ""
    }
  }
}
</script>
<style lang="less">
</style>